<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Network I/O</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<link href="edit68k.css" rel="stylesheet" type="text/css">
</head>

<body class="text">
<p class="heading">Sim68K Network I/O<hr noshade></p>
<p>TRAP #15 is used for I/O. &nbsp;Put the task number in lower 8 bits of D0.</p>

<p><b>&nbsp;Task</b>
<table border=1 cellspacing=0 cellpadding=0 width=697 class="text" style="border-collapse: collapse" bordercolor="#000000">
 <tr>
  <td width="6%">
  <b>&nbsp;100</b></td>
  <td width="94%">
  &nbsp;Configure as network Client. <br>
&nbsp;&nbsp; Pre:<br>
&nbsp;&nbsp;&nbsp;&nbsp; D1.L&nbsp; {31..............16}{15......8}{7......0}<br>
&nbsp;&nbsp;&nbsp;&nbsp; Bits 0-7,&nbsp; 0 for UDP, all other values reserved<br>
&nbsp;&nbsp;&nbsp;&nbsp; Bits 8-15, Reserved for future use<br>
&nbsp;&nbsp;&nbsp;&nbsp; Bits 16-31, Port number<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Port numbers 0-1023 are used for 
	well-known services. Port numbers 1024-65535 may be freely used.<br>
&nbsp;&nbsp;&nbsp;&nbsp; (A2) IP address to connect to as null terminated string 
	(e.g. '192.168.1.100',0) or<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; null 
	terminated domain name (e.g. 'www.easy68k.com',0)<br>
&nbsp;&nbsp; Post:<br>
&nbsp;&nbsp;&nbsp;&nbsp; D0.L is 0 on success, non zero on error<br>
&nbsp;&nbsp;&nbsp;&nbsp; Error codes:<br>
&nbsp;&nbsp;&nbsp;&nbsp; Bits 0-15 Low word <br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 1 - general error<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 2 - network initialization failed<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 3 - invalid socket<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 4 - get host by name failed<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 5 - bind failed<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 6 - connect failed<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 7 - port already in use<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 8 - domain not found<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; All other values reserved<br>
&nbsp;&nbsp;&nbsp;&nbsp; Bits 16-31 High word, extended error code (see below)<br>
&nbsp;&nbsp;&nbsp;&nbsp; (A2) IP address connected to as null terminated string<br>
	<br>
	<br>
	Example:
	<span LANG="EN"><font SIZE="2">
	<p class="sourcecode" style="margin-top: 0; margin-bottom: 0">
	&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; move.b&nbsp; #100,d0&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
	; create network client<br>
	&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; move.l&nbsp; #(2048 &lt;&lt; 16 + 0),d1&nbsp; 
	; port 2048, UDP<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; lea&nbsp;&nbsp;&nbsp;&nbsp; 
	serverIP,a2&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ; IP 
	to connect<br>
	&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; trap&nbsp;&nbsp; &nbsp;#15 <br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ...<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ...</p>
	<p class="sourcecode" style="margin-top: 0; margin-bottom: 0">
	serverIP dc.b&nbsp;&nbsp; '192.168.1.101',0<br>
&nbsp;</p></font>
	<p>
	&nbsp;Visit <a target="_blank" href="http://www.EASy68K.com">www.EASy68K.com</a> 
	for examples.</p></span></td>
 </tr>
 <tr>
  <td width="6%">
  <b>&nbsp;101</b></td>
  <td width="94%">
  &nbsp;Configure as network Server.<br>
&nbsp;May not be configured as Server and Client at the same time. <br>
&nbsp;&nbsp; Pre:<br>
&nbsp;&nbsp;&nbsp;&nbsp; D1.L&nbsp; {31..............16}{15......8}{7......0}<br>
&nbsp;&nbsp;&nbsp;&nbsp; Bits 0-7, 0 for UDP, all other values reserved<br>
&nbsp;&nbsp;&nbsp;&nbsp; Bits 8-15, Reserved for future use<br>
&nbsp;&nbsp;&nbsp;&nbsp; Bits 16-31, Port number<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Port numbers 0-1023 are used for 
	well-known services. Port numbers 1024-65535 may be freely used.<br>
&nbsp;&nbsp; Post:<br>
&nbsp;&nbsp;&nbsp;&nbsp; D0.L is 0 on success, non zero on error<br>
&nbsp;&nbsp;&nbsp;&nbsp; Error codes:<br>
&nbsp;&nbsp;&nbsp;&nbsp; Bits 0-15 <br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 1 - general error<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 2 - network initialization failed<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 3 - invalid socket<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 4 - get host by name failed<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 5 - bind failed<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 6 - connect failed<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 7 - port already in use<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 8 - domain not found<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; All other values reserved<br>
&nbsp;&nbsp;&nbsp;&nbsp; Bits 16-31, extended error code (see below)</td>
 </tr>
 <tr>
  <td width="6%">
  <b>&nbsp;102</b></td>
  <td width="94%">
  &nbsp;Send data<br>
&nbsp; Pre:<br>
&nbsp;&nbsp;&nbsp; D1.L&nbsp; {31..............16}{15..............0}<br>
&nbsp;&nbsp;&nbsp; Bits 0-15, Number of bytes to send<br>
&nbsp;&nbsp;&nbsp; Bits 16-31, Reserved for future use<br>
&nbsp;&nbsp;&nbsp; (A1) data to send<br>
&nbsp;&nbsp;&nbsp; If server<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; (A2) IP address of client as null terminated 
	string (e.g. '192.168.1.100',0)<br>
&nbsp; Post:<br>
&nbsp;&nbsp;&nbsp; D0.L is 0 on success, non zero on error<br>
&nbsp;&nbsp;&nbsp; Bits 0-15<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 1 - send failed<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; All other values reserved<br>
&nbsp;&nbsp;&nbsp; Bits 16-31, extended error code (see below)<br>
&nbsp;&nbsp;&nbsp; D1.L number of bytes sent, may be 0. Unchanged on error. </td>
 </tr>
 <tr>
  <td>
  <b>&nbsp;103</b></td>
  <td width="94%">
  &nbsp;Receive data<br>
&nbsp; Pre:<br>
&nbsp;&nbsp;&nbsp; D1.L&nbsp; {31..............16}{15..............0}<br>
&nbsp;&nbsp;&nbsp; Bits 0-15, Number of bytes to receive.<br>
&nbsp;&nbsp;&nbsp; Bits 16-31, Reserved for future use.<br>
&nbsp;&nbsp;&nbsp; (A1) received buffer, must be large enough to hold D1.W 
	bytes.<br>
&nbsp; Post:<br>
&nbsp;&nbsp;&nbsp; D0.L is 0 on success, non zero on error<br>
&nbsp;&nbsp;&nbsp; Bits 0-15<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 1 - receive failed<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; All other values reserved<br>
&nbsp;&nbsp;&nbsp; Bits 16-31, extended error code (see below)<br>
&nbsp;&nbsp;&nbsp; D1.L number of bytes received. 0 if no data has been 
	received. Unchanged on error.<br>
&nbsp;&nbsp;&nbsp; (A2) IP address of sender as null terminated string.</td>
 </tr>
 <tr>
  <td>
  <b>&nbsp;104</b></td>
  <td width="94%">
  &nbsp;Close connections<br>
&nbsp; Pre:<br>
&nbsp;&nbsp;&nbsp; If TCP server<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; D1.L IP address of connection to close, 0 to 
	close all.<br>
&nbsp; Post:<br>
&nbsp;&nbsp;&nbsp; D0.L is 0 on success, non zero on error</td>
 </tr>
 <tr>
  <td>
  <b>&nbsp;105</b></td>
  <td width="94%">
  &nbsp;Get local IP address<br>
&nbsp; Pre:<br>
&nbsp;&nbsp;&nbsp; The network has been initialized with task 100 or 101<br>
&nbsp; Post:<br>
&nbsp;&nbsp;&nbsp; D0.L is 0 on success, non zero on error<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 1 - get local IP failed<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; All other values reserved<br>
&nbsp;&nbsp;&nbsp; Bits 16-31, extended error code (see below)<br>
&nbsp;&nbsp;&nbsp; (A2) local IP address as null terminated string. Max size 16 
	characters including null.</td>
 </tr>
 </table>
<p>Extended Error Codes<br>
<br>
$2714 - A blocking operation was interrupted<br>
$271D - Socket access permission violation<br>
$2726 - Invalid argument<br>
$2728 - Too many open sockets<br>
$2735 - Operation in progress<br>
$2736 - Operation on non-socket<br>
$2737 - Address missing<br>
$2738 - Message bigger than buffer<br>
$273F - Address incompatible with protocol<br>
$2740 - Address is already in use<br>
$2741 - Address not valid in current context<br>
$2742 - Network is down<br>
$2743 - Network unreachable<br>
$2744 - Connection broken during operation<br>
$2745 - Connection aborted by host software<br>
$2746 - Connection reset by remote host<br>
$2747 - Insufficient buffer space<br>
$2748 - Connect request on already connected socket<br>
$2749 - Socket not connected or address not specified<br>
$274A - Socket already shut down<br>
$274C - Operation timed out<br>
$274D - Connection refused by target<br>
$274E - Cannot translate name<br>
$274F - Name too long<br>
$2750 - Destination host down<br>
$2751 - Host unreachable<br>
$276B - Network cannot initialize, system unavailable<br>
$276D - Network has not been initialized<br>
$2775 - Remote has disconnected</p>
<p>(Refer to Winsock file winerror.h for unlisted error codes )<br>
&nbsp;</p>
</body>
</html>
